package com.tigercar.servicemanagement.controller;

import com.tigercar.common.pojo.PageResult;
import com.tigercar.servicemanagement.pojo.Role;
import com.tigercar.servicemanagement.service.RoleService;
import com.tigercar.servicemanagement.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;

    /**
     * 分页查询角色信息
     * liangjunjie
     * @param curPage 当前页
     * @param pageSize 页大小
     * @param RoleName 查询角色名称搜索条件
     * @return 角色信息列表
     */
    @GetMapping("/system/role/list")
    public ResponseEntity<PageResult<RoleVo>> searchRoleList(
            @RequestParam(value = "curPage",defaultValue = "1")Integer curPage,
            @RequestParam(value = "pageSize",defaultValue = "5")Integer pageSize,
            @RequestParam(value = "name",required = false) String RoleName
    ){
        PageResult<RoleVo> pageResult = roleService.searchRoleList(curPage,pageSize,RoleName);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 删除角色信息
     * liangjunjie
     * @param roleId 删除角色id
     * @return 无
     */
    @DeleteMapping("/system/role/delete")
    public ResponseEntity<Void> deleteRole(@RequestParam("id")Integer roleId){
        roleService.deleteRole(roleId);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
}
